package com.jvyou.app.ds.controller;



import com.jvyou.app.common.domain.model.PageResult;
import com.jvyou.app.ds.domain.dto.VehicleDto;
import com.jvyou.app.ds.domain.entity.Vehicle;
import com.jvyou.app.ds.service.VehicleService;
import org.springframework.web.bind.annotation.*;
import lombok.RequiredArgsConstructor;
import cn.dev33.satoken.annotation.SaCheckPermission;
import com.jvyou.app.common.domain.model.Result;
import com.jvyou.app.common.enums.HttpCodeEnum;

import java.util.List;

/**
 * 教练车基本信息表(Vehicle)表控制层
 *
 * @author 橘柚
 * @since 2025-04-16 10:11:39
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/vehicle")
public class VehicleController  {
    
    private final VehicleService vehicleService;

    @GetMapping("/list")
    @SaCheckPermission("ds:vehicle:list")
    public Result<List<Vehicle>> list(@ModelAttribute VehicleDto vehicleDto) {
        return Result.success(vehicleService.listVehicle(vehicleDto));
    }

    @GetMapping("/page")
    @SaCheckPermission("ds:vehicle:page")
    public Result<PageResult<Vehicle>> page(@ModelAttribute VehicleDto vehicleDto) {
        return Result.success(vehicleService.pageVehicle(vehicleDto));
    }

    /**
     * 通过主键查询教练车
     */
    @GetMapping("/{id}")
    @SaCheckPermission("ds:vehicle:get")
    public Result<Vehicle> selectOne(@PathVariable Long id) {
        return Result.success(vehicleService.getById(id));
    }
    /**
     * 新增教练车
     *
     * @param vehicle 实体对象
     * @return 新增结果
     */
    @PostMapping
    @SaCheckPermission("ds:vehicle:insert")
    public Result<Vehicle> insert(@RequestBody Vehicle vehicle) {
        boolean success = vehicleService.save(vehicle);
        return success ? Result.success(vehicle) : Result.error(HttpCodeEnum.ADD_FAIL);
    }
     /**
     * 修改教练车
     *
     * @param vehicle 实体对象
     * @return 修改结果
     */
    @PutMapping("/updateById")
    @SaCheckPermission("ds:vehicle:update")
    public Result<Boolean> updateById(@RequestBody Vehicle vehicle) {
        boolean success = vehicleService.updateById(vehicle);
        return success ? Result.success(true) : Result.error(HttpCodeEnum.UPDATE_FAIL);
    }
    

    /**
     * 删除数据
     *
     * @param id 主键结合
     * @return 删除结果
     */
    @DeleteMapping("/{id}")
    @SaCheckPermission("ds:vehicle:delete")
    public Result<Boolean> delete(@PathVariable Long id) {
        boolean success = vehicleService.removeById(id);
        return success ? Result.success(true) : Result.error(HttpCodeEnum.DELETE_FAIL);
    }
    
}

